home *** CD-ROM | disk | FTP | other *** search
- Path: spock.asic.sc.ti.com!usenet
- From: "Billy N. Patton" <bpatton@asic.sc.ti.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Help: File counting lines
- Date: Wed, 13 Mar 1996 12:22:25 -0600
- Organization: Texas Instruments, Inc.
- Message-ID: <31471261.106A@asic.sc.ti.com>
- References: <4hni12$qst@bolivia.it.earthlink.net> <4huog1$t8s@news.axess.com>
- NNTP-Posting-Host: bily-linux.asic.sc.ti.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0GoldB1 (WinNT; I)
- CC: bpatton@asic.sc.ti.com
-
- Kamikaze wrote:
- >
- > brunop@earthlink.net (Peter Bruno) wrote:
- >
- > >Does anyone have any suggestions on a fast way to count the number of lines in
- > >a ASCII file. Each line is terminted by a <enter> and all I need to do is
- > >count the number of lines (records) in the file.
- >
- > >The way I've been doing it is by: fgets(row, 128, File); count++;
- > >however, if the line is longer then 128 characters this does not work and it
- > >would seem that there must be a better way of doing it anyway... perhaps by
- > >incrementing the pointer until EOF??
- >
- > >Any assistance would be greatly appreciated...
- >
- > >Thanx,
- >
- > >Peter Bruno
- > >brunop@earthlink.net
- >
- > Yeah use the stream objects, like this
- >
- > ifstream in;
- > int count = 0;
- > char buffer[BUFFER_SIZE );
- >
- > in = open( name_of_file );
- > if ( !in.bad() )
- > {
- > while ( !in.eof() )
- > {
- > getline( buffer, sizeof( buffer ) );
- > count++;
- > }
- > in.close();
- > }
- >
- > Something like this, you get the picture.
-
- Get the gnu stuff and do :
- wc -l file_name
-